﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Role.Entity;

namespace Role.Data
{
    public class WorkFlow_InfoRepository : RoleRepositoryBase, IGetModel<WorkFlow_Info>
    {
        #region IGetModel<WorkFlow_Info> 成员
        public IQueryable<WorkFlow_Info> GetModel()
        {
            return base.GetEntities<WorkFlow_Info>();
        }

        public IQueryable<WorkFlow_Info> GetDetailModel()
        {
            var linq = from data1 in base.GetEntities<WorkFlow_Info>()
                       join workFow in base.GetEntities<WorkFlow>() on data1.WorkFlowID equals workFow.ID
                       join prev in base.GetEntities<WorkFlow_Info>() on data1.PrevNode equals prev.ID into prevlist
                       join next in base.GetEntities<WorkFlow_Info>() on data1.NextNode equals next.ID into nextlist
                       select new WorkFlow_Info_Ext
                       {
                           ID             = data1.ID,
                           Info           = data1.Info,
                           Name           = data1.Name,
                           NextNode       = data1.NextNode,
                           PrevNode       = data1.PrevNode,
                           NextNodeEntity = nextlist.FirstOrDefault(),
                           PrevNodeEntity = prevlist.FirstOrDefault(),
                           WorkFlow       = workFow,
                           WorkFlowID     = data1.WorkFlowID,
                       };
            return linq;
        }

        #endregion
    }
}
